<?php
namespace app\adm\controller;
use think\Controller;
use think\Db;
use think\Request;

/**
 * 后台账户管理
 */
class Admin extends Index{
	public function __construct(Request $request){
		parent::__construct($request);
	}
	/*
	 * 密码管理
	*/
    public function password(Request $request){
    	if(!$request->isAJax()){
            return $this->fetch($request->action(),['title'=>'修改密码']);
        }else{
            $data = Request::instance()->post();
    
            $find = Db::name('auth_user')->where(['uid'=>session('uid')])->find();

           	if($find['loginPassword'] !==strtolower(md5(md5($data['oldpassword'])))){
           		$this->error('旧密码错误');
           	}
           	Db::name('auth_user')->where(['uid'=>session('uid')])->update(['loginPassword'=>strtolower(md5(md5(trim($data['newpassword']))))]);
           	$this->success('修改成功','index/welcome');
        }
    }
}
